var apis = require( '../../cloud/lib/apis' );
var rongrequest = require( '../../cloud/lib/rongrequest' );
var util 		= require( '../../cloud/lib/util' );
var rcResult 	= require( '../../cloud/const' ).result;
var AV = require('leanengine');
exports.getToken = function( userId, name, portraitUri, format, callback ) {
	rongrequest.request( apis['user']['getToken'], {
		userId 		: userId,
		name   		: name,
		portraitUri : portraitUri
	}, format, function(err,result ) {
		return callback(err,result );
	} );
}

exports.refresh = function( userId, name, portraitUri, format, callback ) {
	rongrequest.request( apis['user']['refresh'], {
		userId 		: userId,
		name   		: name,
		portraitUri : portraitUri
	}, format, function( result ) {
		return callback( result );
	} );
}
exports.block = function( userId, minute, format, callback ) {
	rongrequest.request( apis['user']['block'], {
		userId 		: userId,
		minute   		: minute
	}, format, function( result ) {
		return callback( result );
	} );
}
exports.unblock = function( userId, format, callback ) {
	rongrequest.request( apis['user']['unblock'], {
		userId 		: userId
	}, format, function( result ) {
		return callback( result );
	} );
}
exports.blackListAdd = function( userId,blackUserIds, format, callback ) {
	if( !util.validateId( userId ) ) {
		return callback( { code : rcResult.INVALID_GROUPID, message : rcResult.INVALID_GROUPID_MSG }, null );
	}

	var params = { userId : userId};
	if( typeof blackUserIds == 'object' && blackUserIds.length ) {
		rongrequest.requestWithSameFields( apis['user']['blacklistAdd'], params, [ { field : 'blackUserId', values : blackUserIds } ], format, callback );
	}
	else if( typeof blackUserIds == 'string' || typeof blackUserIds == 'number' ) {
		params.blackUserId = blackUserIds;
		rongrequest.request( apis['user']['blacklistAdd'], params, format, callback );
	}
	else {
		throw new Error( "Invalid blackUserIds! The blackUserIds should be either a string, a number, or an non-empty array!" );
	}
}

